/*
 * The common variable types are defined here.
 */
#ifndef COMMON_H
#define COMMON_H

namespace crossbit {

// Macro defininations
#define __X86__

#ifdef __X86__
#define CONTEXT_SAVE 	     __asm__("pusha");
#define CONTEXT_RESTORE	     __asm__("popa");
#elif __MIPS__
#define CONTEXT_SAVE
#define CONTEXT_RESTORE
#else
#define CONTEXT_SAVE
#define CONTEXT_RESTORE
#endif

#define ALL_SIG_OFF		\
	{					\
		if (UTIL::XTSigprocmask(SIG_SETMASK, &GLOBAL::SIG_FULL_SET, NULL))	\
			exit(-1);	\
	}

#define ALL_SIG_ON	\
	{			\
		if (UTIL::XTSigprocmask(GLOBAL::SIG_HOW, &GLOBAL::SIG_ON_SET, &GLOBAL::SIG_ON_OLDSET))	\
			exit(-1);	\
		if (UTIL::XTSigpending(&GLOBAL::SIG_ON_SET))		\
			exit(-1);	\
	}

#define PAGESIZE 	(1<<12)
#define PAGESTART(x)	((x) & ~(XTUint32)(PAGESIZE-1))
#define PAGEALIGN(x) 	(((x) + PAGESIZE - 1) & ~(PAGESIZE-1))
#define PAGEOFFSET(x) 	((x) & (PAGESIZE-1))

#define INLINE  inline
#define FINLINE __attribute__((always_inline))

// Basic value type

    typedef unsigned char       XTUint8;
    typedef char                XTInt8;
    typedef unsigned short      XTUint16;
    typedef short               XTInt16;
    typedef unsigned int        XTUint32;
    typedef int                 XTInt32;
    typedef unsigned long long  XTUint64;
    typedef long long           XTInt64;

    typedef char *              XTPStr;
    typedef const char *        XTCPStr;

    typedef XTUint32            XTMemAddr;
    typedef XTUint8             XTRegNum;

    // Block Size (Byte/HalfXTInt32/XTInt32)
    enum BlockSize {
        BYTE,       // 8 bit
        HALFWORD,   // 16 bit
        WORD,       // 32 bit
        DWORD,      // 64 bit
        FLOAT,      // 32 bit, floating point
        DOUBLE,     // 64 bit, floating point
    };

} // crossbit

#endif
